package com.wtj.user.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wtj.user.domain.User;
import com.wtj.user.mapper.UserMapper;
import com.wtj.user.service.UserService;
import com.wtj.user.vo.UserPageReq;
import com.wtj.user.vo.UserPageResp;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author wangt
* @description 针对表【sys_user(用户表)】的数据库操作Service实现
* @createDate 2024-11-15 22:39:36
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public List<UserPageResp> getUserPage(UserPageReq userPageReq) {
        // 创建分页对象 (Page 是 MyBatis-Plus 提供的分页对象)
        Page<User> page = new Page<>(userPageReq.getPageNum(), userPageReq.getPageSize());

        // 构造查询条件
        LambdaQueryWrapper<User> userLambdaQueryWrapper = Wrappers.lambdaQuery();

        // 执行分页查询
        IPage<User> userPage = userMapper.selectPage(page, userLambdaQueryWrapper);

        // 获取分页结果列表
        List<User> userList = userPage.getRecords();
        return BeanUtil.copyToList(userList, UserPageResp.class);

    }

    @Override
    public UserPageResp getUserById(Long id) {
        User userById = userMapper.getUserById(id);
        return BeanUtil.toBean(userById, UserPageResp.class);
    }
}




